package servlet;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import DTO.Product;
import  BLL.BProduct;
import java.io.PrintWriter;
import java.util.Date;

/**
 *
 * @author Vien-IT
 */
public class AddProduct extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
   

    
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
         request.setCharacterEncoding("UTF-8");  
       response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String productName = request.getParameter("productName");
        String productInfo = request.getParameter("productInfo");
        String productImage = request.getParameter("productImage");
        String productNumber = request.getParameter("productNumber");
        String productprice = request.getParameter("productprice");
         String category = request.getParameter("category");
        
         Product product = new Product();
        product.setName(productName);
        product.setInfo(productInfo);
        product.setImge(productImage);
        product.setNumberOfProduct(Integer.parseInt(productNumber));
        product.setPrice(productprice);
        product.setBestSale(0);
        product.setCategoryId(Integer.parseInt(category));
        product.setDateCreate(new Date());
       
             
         
        
        new BProduct().insert(product);
        response.sendRedirect("add_product.jsp");
        
        
        
        
        
       
    }
}
    

